package wc;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class WordCountMapReduce {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        // 创建配置对象
        Configuration conf = new Configuration();
        // 创建job对象
        Job job = Job.getInstance(conf, "wordcount");
        // 设置运行job的主类
        job.setJarByClass(WordCountMapReduce.class);
        // 设置mapper类
        job.setMapperClass(WordCountMapper.class);
        // 设置reducer类
        job.setReducerClass(WordCountReducer.class);
        // 设置mapper输出的key value
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        // 设置reducer输出的key value
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        // 设置输入的路径
        FileInputFormat.setInputPaths(job, new Path(""));
        FileOutputFormat.setOutputPath(job, new Path(""));
        // 提交job
        boolean b = job.waitForCompletion(true);
        if (!b) {
            System.out.println("This task is failed");
        }
    }
}
